Skip to content

Fix/router child dynamic prefix pr#5655

Open
rjharmon wants to merge 5 commits into
DioxusLabs:mainfrom
rjharmon:fix/router-child-dynamic-prefix-pr
Open

Fix/router child dynamic prefix pr#5655
rjharmon wants to merge 5 commits into
DioxusLabs:mainfrom
rjharmon:fix/router-child-dynamic-prefix-pr

Conversation

@rjharmon

@rjharmon rjharmon commented Jul 1, 2026

Copy link
Copy Markdown

#[child] with dynamic prefixes and depth-2+ chains

Intent

Make #[child("/path/:dyn")] and multi-level #[child] composition work end-to-end at parse, render, and Link href generation.

  • End-to-end support for #[child("/path/:dyn")]: parent dynamic-segment values now round-trip through parse, render, and Link href correctly.
  • Support for 2+ (arbitrary) levels of #[child] composition, so deeply nested child routers no longer drop the deepest dynamic at render or drop outer captured values from Link hrefs.
  • #[child("/:..rest")] composes with children that carry only query or hash specs

Approach

Preserves PR #5613's query/hash forwarding and PR #4994's child-router layout shape; layered on
top of both. Backstory:

PR #5613 built trailing from all remaining URL segments and delegated the whole
thing to child::from_str FIRST, then parsed the parent's route-segment definitions inside the
Ok arm. So its ordering was parent-last

Implementation changed so the parent route's (dynamic) segment definition are consumed via the
nested try_parse chain first, and child::from_str(&trailing) runs only after segments has been
advanced to the child's tail.

test notes

  • Depth-2 Link href exercises the Arc<dyn Fn(R) -> String> widening: the emitted closure move-captures the parent's dynamic-segment values.
  • Depth-3 Link href exercises format_route_via_chain<R>, which walks any outer ChildRouteMapping<R> chain. The multi-level composition the depth-2 test cannot reach.

@rjharmon
rjharmon requested a review from a team as a code owner July 1, 2026 02:12
rjharmon added 3 commits July 16, 2026 13:49
* widen ChildRouteMapping.format_route_as_root_route to Arc<dyn Fn>
* add parse_route_via_chain helper for depth-2+ child router chains
* add format_route_via_chain helper, symmetric to parse_route_via_chain,
  so format-side closure composition walks through multiple outer
  ChildRouteMapping<R> mappings at depth 3 or more
* walk parent dynamic segments before delegating to child::from_str,
  preserving DioxusLabs#5613's raw_query and raw_hash forwarding
* emit catch-all writes through a Display wrapper so
#[child("/:..rest")]
  composes with children that have only query or hash specs
* drain catch-all without consuming the source segments iterator
* parsing: dynamic-prefix child round-trip via to_string, including
  a percent-encoded value subcase
* parsing: dynamic-prefix child preserves the query channel
* parsing: dynamic-prefix child preserves the hash channel
* parsing: catch-all parent composes with query-only child
* parsing: catch-all parent with typed element type round-trips
* parsing: typed parent dynamic segment surfaces parent parse error
* via_ssr: render under dynamic parent prefix
* via_ssr: depth-2 chain preserves the deepest dynamic, and Link href
  captures parent dynamic at depth 2
* via_ssr: depth-3 chain preserves the deepest dynamic two hops down
* via_ssr: depth-3 Link href captures both parent dynamics
@rjharmon
rjharmon force-pushed the fix/router-child-dynamic-prefix-pr branch from abb710a to 6807560 Compare July 16, 2026 21:02
rjharmon added 2 commits July 16, 2026 14:29
…le derive

Given [#nest("/with/:param")]... #[end_nest] when a layout opened inside
the nest is still open; requires explicit #[end_layout] before a
following variant.

- #[end_layout]/#[end_nest] aren't needed unless there's another variant
- a following variant was generated with the nesting parameter expected,
  producing a unbound-identifier E0425 (mysterious looking because it's
  in generated code)
- gives a direct diagnostic instead of the mystery error
@rjharmon
rjharmon force-pushed the fix/router-child-dynamic-prefix-pr branch from 6807560 to 0a369f8 Compare July 16, 2026 21:29
@rjharmon

Copy link
Copy Markdown
Author

Redundantly, I'll say:

  • Added diagnostic error for subroutes missing args
  • Added diagnostic error for missing #[end_layout] before #[end_nest] before later-route-variant

Rebased on latest main branch too. Sorry for the extra force-push; I'd forgotten to run cargo fmt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant